<template>
	<view class="">
		<bg-video></bg-video>
		<cu-custom bgColor="bg-main" :isBack="false">
			<block slot="content">{{navpagetitle[currentnav]}}</block>
		</cu-custom>
		<view :style="{paddingBottom:CustomBar + 'px'}">
			<home v-if="currentnav == 'home'"></home>
			<wd v-if="currentnav == 'wd'"></wd>
		</view>
		<view style="z-index: 9;" class="w-100 fixed bottom0 left0 bg-white ">
			<view v-for="(nav, index) in navbars" :key="index" class="w-50 inline-block flex justify-center bg-white">
				<view @tap="currentnav = nav.tab"
					class="flex flex-direction text-main justify-center align-center padding-bottom-sm">
					<text class="text-sl">
						<text :class="currentnav == nav.tab ? nav.cla : nav.cl"></text>
					</text>
					<text :class="currentnav == nav.tab ? 'text-main' : 'text-black'">{{nav.title}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import home from "./home.vue";
	import wd from "./wd.vue";
	export default {
		components: {
			home,
			wd
		},
		data: function() {
			return {
				adz: this.store.state.dz,
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				currentnav: "home",
				navpagetitle: {
					home: "门店",
					wd: "店长",
				},
				navbars: [{
						cl: "iconfont icon-shouye",
						cla: "iconfont icon-shouye-tianchong",
						tab: "home",
						title: "门店"
					},
					{
						cl: "iconfont icon-wode",
						cla: "iconfont icon-wode-tianchong",
						tab: "wd",
						title: "店长"
					},
				]


			}
		},
		created: function() {
			this.init();
		},
		onPullDownRefresh: function() {
			this.init();
			uni.stopPullDownRefresh();
		},
		methods: {
			init: function() {
				this.loadDz();
			},
			// toSet: function() {
			// 	uni.navigateTo({
			// 		url: '/pages/wd/rllr'
			// 	});
			// },
			toMdxx: function(storeid) {
				uni.navigateTo({
					url: "/pages/cdz/md/mdxx?storeid=" + storeid
				});
			},
			toFj: function() {
				uni.navigateTo({
					url: "/pages/cdz/fj/list"
				});
			},
			toYy: function() {
				uni.navigateTo({
					url: "/pages/cdz/yy/search"
				});
			},
			toMdEdit: function(storeid) {
				uni.navigateTo({
					url: "/pages/cdz/md/edit?storeid=" + storeid
				});
			},
			removeMd: function(storeid, index) {
				this.api("/md/info/remove").send({
					storeid,
				}).then(data => {
					this.mds.splice(index, 1);
					this.message.info("删除成功");
				});
			},
			newMd: function() {
				this.mds.push({
					storeid: "",
					sname: "",
					dzid: this.adz.dzid,
					stu: "U"
				});
			},
			saveMd: function(index) {

				let md = this.mds[index];
				if (md.sname.length == 0) {
					this.message.info("门店名必须输入");
					return;
				} else if (md.sname.length > 20) {
					this.message.info("门店名太长了");
					return;
				}

				this.api("/md/info").send({
					astore: this.md,
				}).then(data => {
					this.mds[index] = data.astore;
					this.$forceUpdate();
				});
			},
			loadDz: function() {
				this.mds = [];
				this.api("/dz/info/get").send({
					dzid: this.adz.dzid
				}).then(data => {
					for (let index in data.stores) {
						let record = data.stores[index];
						if (record.distance) {
							record.distance = this.util.formatDistance(record.distance);
						}
						this.mds.push(record);
					}
					this.fjnumber = data.fjnumber;
					this.yynumber = data.yynumber;
				});


			},
			toNewMd: function() {
				if (!this.store.state.dz.tx) {
					this.message.info("请先设置人脸");
					return;
				}

				if (!this.store.state.dz.dname) {
					this.message.info("请先设置昵称");
					return;
				}
				uni.navigateTo({
					url: "/pages/cdz/md/new"
				});
			}
		}
	}
</script>

<style>
</style>